<template>
    <div>
        <div class="form-uplod">
            <div class="join-in-uplod">
                <img :src="imgUrl" alt="">
                <i></i>
                <input type="file" @change="uploads">
                <input type="hidden" v-model="upload.imgInput" >
            </div>
            <p>身份证正面</p>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                upload:{
                    imgInput:'',
                }
            }
        },
        methods: {
            uploads(e){
                const file = e.target.files[0];//获取到当前文件对象

                let URL = window.URL||window.webkitURL; // 与上传没有关系（可选）
                this.imgUrl = URL.createObjectURL(file); // 这是为了显示图片而已， 与上传没有关系（可选）
                
                // 传递一个 FormData 对象 即可 
                let formData = new FormData();
                formData.append('file',file); // 'file' 可变 相当于 input 表单的name 属性
                //console.log(formData.append('file',file))
                this.$http.post('/ImgFile',formData).then(rs=>{
                    console.log(rs.data)
                    this.upload.imgInput = rs.data
                }).catch(err=>{
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped>
.hide {
    display: none;
}

.img-item {
    width: 4.4rem;
    height: 3.75rem;
    float: left;
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.img-item img {
    width: 100%;
    height: 100%;
}
.active-pic {
    font-size: 0.6rem;
    color: #9b9b9b;
    padding: 0 1rem 0 1.5rem;
    margin-top: 1rem;
}

.add-pic {
    background: #f3f3f3;
    width: 4.4rem;
    height: 3.75rem;
    float: left;
    margin-left: 1.5rem;
    margin-top: 0.5rem;
    text-align: center;
    font-size: 2rem;
    line-height: 3.5rem;
    color: #979797;
    position: relative;
}

.add-pic input {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    opacity: 0;
}

</style>